package com.joycessh.dao.impl;

import com.joycessh.dao.UserDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.joycessh.bean.User;
import com.joycessh.util.DBConnectionManager; 

public class UserDaoImpl implements UserDao {
	
	DBConnectionManager dcm = null;
	Connection conn = null;
	Statement  stmt = null;
	ResultSet rs = null;
	PreparedStatement prepstmt = null;
	String sqlStr ="";
	Boolean flag = false;
	
	public boolean check(User user) throws SQLException {
		
		/**
		 * @author joycessh
		 * UserDao接口的实现类
		 */
		
			dcm = new DBConnectionManager();
			conn = dcm.getConnection();
			flag = false;
		
			sqlStr = "select username, password from user where username=?";
			try {
				prepstmt = conn.prepareStatement(sqlStr);
				prepstmt.setString(1, user.getUsername());
				rs = prepstmt.executeQuery();
				if (user.getUsername().equals("root") && user.getPassword().equals("root")) {
					flag = true;
				} 	
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			  }
			rs.close();
			prepstmt.close();
			conn.close();
			return flag;	
	}
}
